﻿using Prism.Events;
using Prism.Regions;
using SoonCode.FocusTest.Events;
using SoonCode.FocusTest.ViewModels;
using SoonCode.FocusTest.Views;

namespace SoonCode.FocusTest.Views
{
    /// <summary>
    /// FullScreenView.xaml 的交互逻辑
    /// </summary>
    public partial class FullScreenView : BaseWindow
    {
        private string regionName = "studentFullScreenRegion";
        private IEventAggregator aggregator;
        private IRegionManager regionManager;
        public FullScreenView(IEventAggregator aggregator)
        {
            this.regionManager = (new RegionManager()).CreateRegionManager();
            this.aggregator = aggregator;
            regionManager.RegisterViewWithRegion(regionName, typeof(AnswerItemGFull));
            InitializeComponent();
            this.Closing += FullScreenView_Closing;
            this.Loaded += FullScreenView_Loaded;
        }

        private void FullScreenView_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            aggregator.GetEvent<CloseStudentFullScreenEvent>().Subscribe(() =>
            {
                this.Close();
            });
        }
        private void FullScreenView_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }
        
        public void Show(string viewName)
        {
            this.regionManager.RequestNavigate(regionName, viewName);
            ScreenManager.Instance.Show(this.Owner,this,1);
        }

    }
}
